﻿using LxCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LxCore
{
    public class UserFieldCenter : JsObject
    {
        public JsIdentifyList<UserField.Double> Scalar = new();
        public JsIdentifyList<UserField.Vector> Vector = new(); 
        public override void FromJsonKV(string key, IJsonReader jsReader)
        {
            switch (key)
            {
                case nameof(Scalar): jsReader.ReadList(Scalar, t => new UserField.Double()); break;
                case nameof(Vector): jsReader.ReadList(Vector, t => new UserField.Vector()); break;
                default: base.FromJsonKV(key, jsReader); break;
            }
        }
        public override void ToJsonKV(IJsonWriter writer)
        {
            base.ToJsonKV(writer);
            if (Scalar.Count > 0)
            {
                writer.WriteList(nameof(Scalar), Scalar);
            }
            if (Vector.Count > 0)
            {
                writer.WriteList(nameof(Vector), Vector);
            }
        }
    }
}
